home *** CD-ROM | disk | FTP | other *** search
/ Internet Surfer 2.0 / Internet Surfer 2.0 (Wayzata Technology) (1996).iso / pc / textfile / faqs / puzz_faq / part03 < prev    next >
Encoding:
Internet Message Format  |  1992-12-26  |  52.5 KB

  1. Xref: bloom-picayune.mit.edu rec.puzzles:18138 news.answers:3070
  2. Newsgroups: rec.puzzles,news.answers
  3. Path: bloom-picayune.mit.edu!snorkelwacker.mit.edu!spool.mu.edu!uunet!questrel!chris
  4. From: uunet!questrel!chris (Chris Cole)
  5. Subject: rec.puzzles FAQ, part 3 of 15
  6. Message-ID: <puzzles-faq-3_717034101@questrel.com>
  7. Followup-To: rec.puzzles
  8. Summary: This posting contains a list of
  9.      Frequently Asked Questions (and their answers).
  10.      It should be read by anyone who wishes to
  11.      post to the rec.puzzles newsgroup.
  12. Sender: chris@questrel.com (Chris Cole)
  13. Reply-To: uunet!questrel!faql-comment
  14. Organization: Questrel, Inc.
  15. References: <puzzles-faq-1_717034101@questrel.com>
  16. Date: Mon, 21 Sep 1992 00:08:46 GMT
  17. Approved: news-answers-request@MIT.Edu
  18. Expires: Sat, 3 Apr 1993 00:08:21 GMT
  19. Lines: 1353
  20.  
  21. Archive-name: puzzles-faq/part03
  22. Last-modified: 1992/09/20
  23. Version: 3
  24.  
  25. ==> arithmetic/digits/sesqui.s <==
  26. Let's represent this number as  a*10^n+b,  where 1<=a<=9 and
  27. b < 10^n.  Then the condition to be satisfied is:
  28.  
  29. 3/2(a*10^n+b) = 10b+a
  30.  
  31.   3(a*10^n+b) = 20b+2a
  32.  
  33.    3a*10^n+3b = 20b+2a
  34.  
  35.   (3*10^n-2)a = 17b
  36.  
  37.             b = a*(3*10^n-2)/17
  38.  
  39. So we must have 3*10^n-2 = 0 (mod 17) (since a is less than 10, it
  40. cannot contribute the needed prime 17 to the factorization of 17b).
  41. (Also, assuming large n, we must have a at most 5 so that b < 10^n will
  42. be satisfied, but note that we can choose a=1).  Now,
  43.  
  44. 3*10^n-2 = 0 (mod 17)
  45.  
  46. 3*10^n = 2 (mod 17)
  47.  
  48. 10^n = 12 (mod 17)
  49.  
  50. A quick check shows that the smallest n which satisfies this is 15
  51. (the fact that one exists was assured to us because 17 is prime).  So,
  52. setting n=15 and a=1 (obviously) gives us b=176470588235294, so the
  53. number we are looking for is
  54.  
  55.                         1176470588235294
  56.  
  57. and, by the way, we can set a=2 to give us the second smallest such
  58. number,
  59.                         2352941176470588
  60.  
  61. Other things we can infer about these numbers is that there are 5 of
  62. them less than 10^16, 5 more less than 10^33, etc.
  63.  
  64. ==> arithmetic/digits/squares/leading.7.to.8.p <==
  65. What is the smallest square with leading digit 7 which remains a square
  66. when leading 7 is replaced by an 8?
  67.  
  68. ==> arithmetic/digits/squares/leading.7.to.8.s <==
  69. x=2996282391593370361328125
  70. y=2824483699753370361328125
  71. x^2=8977708170172487211329625006796419620513916015625
  72. y^2=7977708170172487211329625006796419620513916015625
  73.  
  74. ==> arithmetic/digits/squares/length.22.p <==
  75. Is it possible to form two numbers A and B from 22 digits such that
  76. A = B^2?  Of course, leading digits must be non-zero.
  77.  
  78. ==> arithmetic/digits/squares/length.22.s <==
  79. No, the number of digits of A^2 must be of the form 3n or 3n-1.
  80.  
  81. ==> arithmetic/digits/squares/length.9.p <==
  82. Is it possible to make a number and its square, using the digits from 1 through
  83. 9 exactly once?
  84.  
  85. ==> arithmetic/digits/squares/length.9.s <==
  86. 567 and 854.
  87.  
  88. ==> arithmetic/digits/squares/three.digits.p <==
  89. What squares consist entirely of three digits (e.g., 1, 4, and 9)?
  90.  
  91. ==> arithmetic/digits/squares/three.digits.s <==
  92. The full set of solutions up to 10**12 is
  93.               1 ->                            1
  94.               2 ->                            4
  95.               3 ->                            9
  96.               7 ->                           49
  97.              12 ->                          144
  98.              21 ->                          441
  99.              38 ->                         1444
  100.             107 ->                        11449
  101.             212 ->                        44944
  102.           31488 ->                   9914 94144
  103.           70107 ->                  49149 91449
  104.         3 87288 ->               14 99919 94944
  105.       956 10729 ->          9 14141 14499 11441
  106.      4466 53271 ->        199 49914 44949 99441
  107.     31487 17107 ->       9914 41941 99144 49449
  108.   2 10810 79479 ->    4 44411 91199 99149 11441
  109.  
  110. If the algorithm is used in the form I presented it before, generating
  111. the whole set P_n before starting on P_{n+1}, the store requirements
  112. begin to become embarassing. For n>8 I switched to a depth-first
  113. strategy, generating all the elements in P_i (i=9..12) congruent to
  114. a particular x in P_8 for each x in turn. This means the solutions
  115. don't come out in any particular order, of course. CPU time was 16.2
  116. seconds (IBM 3084).
  117.  
  118. In article <1990Feb6.025205.28153@sun.soe.clarkson.edu>, Steven
  119. Stadnicki suggests alternate triples of digits, in particular {1,4,6}
  120. (with many solutions) and {2,4,8} (with few). I ran my program on
  121. these as well, up to 10**12 again:
  122.               1 ->                            1
  123.               2 ->                            4
  124.               4 ->                           16
  125.               8 ->                           64
  126.              12 ->                          144
  127.              21 ->                          441
  128.              38 ->                         1444
  129.             108 ->                        11664
  130.             119 ->                        14161
  131.             121 ->                        14641
  132.             129 ->                        16641
  133.             204 ->                        41616
  134.             408 ->                      1 66464
  135.             804 ->                      6 46416
  136.            2538 ->                     64 41444
  137.            3408 ->                    116 14464
  138.            6642 ->                    441 16164
  139.           12908 ->                   1666 16464
  140.           25771 ->                   6641 44441
  141.           78196 ->                  61146 14416
  142.           81619 ->                  66616 61161
  143.         3 33858 ->               11 14611 64164
  144.      2040 00408 ->         41 61616 64641 66464
  145.      6681 64962 ->        446 44441 64444 61444
  146.      8131 18358 ->        661 16146 41166 16164
  147.     40182 85038 ->      16146 61464 66146 61444  (Steven's last soln.)
  148.   1 20068 50738 ->    1 44164 46464 46111 44644
  149.   1 26941 38988 ->    1 61141 16464 66616 64144
  150.   1 27069 43631 ->    1 61466 41644 14114 64161
  151.   4 01822 24262 ->   16 14611 14664 16614 44644
  152.   4 05784 63021 ->   16 46611 66114 66644 46441
  153.  78 51539 12392 -> 6164 66666 14446 44111 61664
  154. and
  155.               2 ->                            4
  156.              22 ->                          484
  157.             168 ->                        28224
  158.             478 ->                      2 28484
  159.            2878 ->                     82 82884 (Steven's last soln.)
  160.      2109 12978 ->         44 48428 42888 28484
  161. (so the answer to Steven's "Are there any more at all?" is "Yes".)
  162.  
  163. The CPU times were 42.9 seconds for {1,4,6}, 18.7 for {2,4,8}. This
  164. corresponds to an interesting point: the abundance of solutions for
  165. {1,4,6} is associated with abnormally large sets P_n (|P_8| = 16088
  166. for {1,4,6} compared to |P_8| = 5904 for {1,4,9}) but the deficiency
  167. of solutions for {2,4,8} is *not* associated with small P_n's (|P_8|
  168. = 6816 for {2,4,8}). Can anyone wave a hand convincingly to explain
  169. why the solutions for {2,4,8} are so sparse?
  170.  
  171. I suspect we are now getting to the point where an improved algorithm
  172. is called for. The time to determine all the n-digit solutions (i.e.
  173. 2n-digit squares) using this last-significant-digit-first is essentially
  174. constant * 3**n. Dean Hickerson in <90036.134503HUL@PSUVM.BITNET>, and
  175. Ilan Vardi in <1990Feb5.214249.22811@Neon.Stanford.EDU>, suggest using
  176. a most-significant-digit-first strategy, based on the fact that the
  177. first n digits of the square determine the (integral) square root; this
  178. also has a running time constant * 3**n. Can one attack both ends at
  179. once and do better?
  180.  
  181. Chris Thompson
  182. JANET:    cet1@uk.ac.cam.phx
  183. Internet: cet1%phx.cam.ac.uk@nsfnet-relay.ac.uk
  184.  
  185. Hey guys, what about
  186.  
  187. 648070211589107021 ^ 2 = 419994999149149944149149944191494441
  188.  
  189. This was found by David Applegate and myself (about 5 minutes on a DEC 3100,
  190. program in C).
  191.  
  192. This is the largest square less than 10^42 with the 149-property; checking
  193. took a bit more than an hour of CPU time.
  194.  
  195. As somebody suggested, we used a combined most-significant/least-significant
  196. digits attack.  First we make a table of p-digit prefixes (most significant
  197. p digits) that could begin a root whose square has the 149 property in its
  198. first p digits.  We organize this table into buckets by the least
  199. significant q digits of the prefixes.  Then we enumerate the s digit
  200. suffixes whose squares have the 149 property in their last s digits.  For
  201. each such suffix, we look in the table for those prefixes whose last q
  202. digits match the first q of the suffix.  For each match, we consider the p +
  203. s - q digit number formed by overlapping the prefix and the suffix by q
  204. digits.  The squares of these overlap numbers must contain all the squares
  205. with the 149 property.
  206.  
  207. The time expended is O(3^p) to generate the prefix table, O(3^s) to
  208. enumerate the suffixes, and O(3^(p+s) / 10^q) to check the overlaps (being
  209. very rough and ignoring the polynomial factors) By judiciously chosing p, q,
  210. and s, we can fix things so that each bucket of the table has around O(1)
  211. entries: set q = p log10(3).  Setting p = s, we end up looking for squares
  212. whose roots have n = 2 - log10(3) digits, with an algorithm that takes time
  213. O( 3 ^ [n / (2 - log10(3)]) ), roughly time O(3^[.66n]).  Compared to the
  214. O(3^n) performance of either single-ended algorithm, this lets us check 50%
  215. more digits in the same amount of time (ignoring polynomial factors).  Of
  216. course, the space cost of the combined-ends method is high.
  217.  
  218. -- Guy and Dave
  219. -- 
  220. Guy Jacobson              School of Computer Science
  221. Carnegie Mellon     arpanet : guy@cs.cmu.edu
  222. Pittsburgh, PA  15213    csnet   : Guy.Jacobson%a.cs.cmu.edu@csnet-relay
  223. (412) 268-3056        uucp    : ...!{seismo, ucbvax, harvard}!cs.cmu.edu!guy
  224.  
  225. Here is an algorithm which takes O(sqrt(n)log(n)) steps to find all perfect
  226. squares < n whose only digits are 1, 4 and 9.
  227.  
  228. This doesn't sound too great *but* it doesn't use a lot of memory and only
  229. requires addition and <.  Also, the actual run time will depend on where the
  230. first non-{1,4,9} digit appears in each square.
  231.  
  232.     set n = 1
  233.     set odd = 1
  234.  
  235.     while(n < MAXVAL)
  236.     {
  237.         if(all digits of n are in {1,4,9})
  238.         {
  239.             print n
  240.         }
  241.  
  242.         add 2 to odd
  243.         add odd to n
  244.     }
  245.  
  246. This works because (X+1)^2 - x^2 = 2x+1.
  247. That is, if you start with 0 and add successive odd
  248. numbers to it you get 0+1=1, 1+3=4, 4+5=9, 9+7=16 etc.
  249. I've started the algorithm at 1 for convenience.
  250.  
  251. The "O" value comes from looking at at most all digits
  252. (log(n)) of all perfect squares < n (sqrt(n) of them)
  253. at most a constant number of times. 
  254.  
  255. I didn't save the articles with algorithms claiming to be
  256. O(3^log(n)) so I don't know if their calculations needed
  257. to (or did) account for multiplication or sqrt() of large
  258. numbers.  O(3^log(n)) sounds reasonable so I'm going to
  259. assume they did unless I hear otherwise.
  260.  
  261. Any comments? Please email if you just want to refresh my memory
  262. on the other algorithms.
  263.  
  264. Andrew Charles
  265. acgd@ihuxy.ATT.COMM
  266.  
  267. ==> arithmetic/digits/squares/twin.p <==
  268. Let a twin be a number formed by writing the same number twice,
  269. for instance, 81708170 or 132132.  What is the smallest square twin?
  270.  
  271. ==> arithmetic/digits/squares/twin.s <==
  272. 1322314049613223140496 = 36363636364 ^ 2.
  273.  
  274. The key to solving this puzzle is looking at the basic form of these
  275. "twin" numbers, which is some number k = 1 + 10^n multiplied by some number
  276. a < 10^n. If ak is a perfect square, k must have some repeated factor,
  277. since a<k. Searching the possible values of k for one with a repeated factor
  278. eventually turns up the number 1 + 10^11 = 11^2 * 826446281.
  279. So, we set a=826446281 and ak = 9090909091^2 = 82644628100826446281,
  280. but this needs leading zeros to fit the pattern. So, we multiply by a suitable
  281. small square (in this case 16) to get the above answer.
  282.  
  283. ==> arithmetic/digits/sum.of.digits.p <==
  284. Find sod ( sod ( sod (4444 ^ 4444 ) ) ).
  285.  
  286. ==> arithmetic/digits/sum.of.digits.s <==
  287. let X = 4444^4444
  288.  
  289. sod(X) <= 9 * (# of digits) < 145900
  290. sod(sod(X)) <= sod(99999) = 45
  291. sod(sod(sod(X))) <= sod(39) = 12
  292.  
  293. but sod(sod(sod(X))) = 7 (mod 9)
  294.  
  295. thus sod(sod(sod(X))) = 7
  296.  
  297. ==> arithmetic/digits/zeros/factorial.p <==
  298. How many zeros are in the decimal expansion of n!?
  299.  
  300. ==> arithmetic/digits/zeros/factorial.s <==
  301. The general answer to the question
  302. "what power of p divides x!" where p is prime
  303. is (x-d)/(p-1) where d is the sum of the digits of (x written in base p).
  304.  
  305. So where p=5, 10 is written as 20 and is divisible by 5^2 (2 = (10-2)/4);
  306. x to base 10:     100    1000    10000    100000     1000000
  307. x to base 5:      400   13000   310000  11200000   224000000
  308. d          :        4       4        4         4           8
  309. trailing 0s in x!  24     249     2499     24999      249998
  310.  
  311. ==> arithmetic/digits/zeros/lsd.factorial.p <==
  312. What is the least significant non-zero digit in the decimal expansion of n!?
  313.  
  314. ==> arithmetic/digits/zeros/lsd.factorial.s <==
  315. Reduce mod 10 the numbers 2..n and then cancel out the
  316. required factors of 10. The final step then involves
  317. computing 2^i*3^j*7^k mod 10 for suitable i,j and k. 
  318.  
  319. A small program that performs this calculation is appended. Like the
  320. other solutions, it takes O(log n) arithmetic operations.
  321.  
  322. -kym
  323. ===
  324.  
  325. #include<stdio.h>
  326. #include<assert.h>
  327.  
  328. int    p[6][4]={
  329.     /*2*/    2,    4,    8,    6,
  330.     /*3*/    3,    9,    7,    1,
  331.     /*4*/    4,    6,    4,    6,
  332.     /*5*/    5,    5,    5,    5,
  333.     /*6*/    6,    6,    6,    6,
  334.     /*7*/    7,    9,    3,    1,
  335.     };
  336.  
  337. main(){
  338.     int    i;
  339.     int n;
  340.  
  341.     for(n=2;n<1000;n++){
  342.         i=lsdfact(n);
  343.         printf("%d\n",i);
  344.         }
  345.  
  346.     exit(0);
  347.     }
  348.  
  349. lsdfact(n){
  350.     int    a[10];
  351.     int    i;
  352.     int    n5;
  353.     int    tmp;
  354.  
  355.     for(i=0;i<=9;i++)a[i]=alpha(i,n);
  356.  
  357.     n5=0;
  358. /* NOTE: order is important in following */
  359. l5:;
  360.     while(tmp=a[5]){    /* cancel factors of 5 */
  361.         n5+=tmp;
  362.         a[1]+=(tmp+4)/5;
  363.         a[3]+=(tmp+3)/5;
  364.         a[5]=(tmp+2)/5;
  365.         a[7]+=(tmp+1)/5;
  366.         a[9]+=(tmp+0)/5;
  367.         }
  368. l10:;
  369.     if(tmp=a[0]){
  370.         a[0]=0;    /* cancel all factors of 10 */
  371.         for(i=0;i<=9;i++)a[i]+=alpha(i,tmp);
  372.         }
  373.     if(a[5]) goto l5;
  374.     if(a[0]) goto l10;
  375.  
  376. /* n5 == number of 5's cancelled; 
  377.    must now cancel same number of factors of 2 */
  378.     i=ipow(2,a[2]+2*a[4]+a[6]+3*a[8]-n5)*
  379.         ipow(3,a[3]+a[6]+2*a[9])*
  380.         ipow(7,a[7]);
  381.     assert(i%10);    /* must not be zero */
  382.     return    i%10;
  383.     }
  384.  
  385. alpha(d,n){
  386. /* number of decimal numbers in [1,n] ending in digit d */
  387.     int tmp;
  388.     tmp=(n+10-d)/10;
  389.     if(d==0)tmp--;    /* forget 0 */
  390.     return tmp;
  391.     }
  392.  
  393. ipow(x,y){
  394. /* x^y mod 10 */
  395.     if(y==0) return 1;
  396.     if(y==1) return x;
  397.     return p[x-2][(y-1)%4];
  398.     }
  399.  
  400.  
  401.  
  402.  
  403. ==> arithmetic/digits/zeros/million.p <==
  404. How many zeros occur in the numbers from 1 to 1,000,000?
  405.  
  406. ==> arithmetic/digits/zeros/million.s <==
  407. In the numbers from 10^(n-1) through 10^n - 1, there are 9 * 10^(n-1)
  408. numbers of n digits each, so 9(n-1)10^(n-1) non-leading digits, of
  409. which one tenth, or 9(n-1)10^(n-2), are zeroes.  When we change the
  410. range to 10^(n-1) + 1 through 10^n, we remove 10^(n-1) and put in
  411. 10^n, gaining one zero, so
  412.  
  413.     p(n) = p(n-1) + 9(n-1)10^(n-2) + 1 with p(1)=1.
  414.  
  415. Solving the recurrence yields the closed form
  416.  
  417.     p(n) = n(10^(n-1)+1) - (10^n-1)/9.
  418.  
  419. For n=6, there are 488,895 zeroes, 600,001 ones, and 600,000 of all other
  420. digits.
  421.  
  422. ==> arithmetic/magic.squares.p <==
  423. Are there large squares, containing only consecutive integers, all of whose
  424. rows, columns and diagonals have the same sum?  How about cubes?
  425.  
  426. ==> arithmetic/magic.squares.s <==
  427. Here is an 8x8 example:
  428.  
  429. 01 56 48 25 33 24 16 57
  430. 63 10 18 39 31 42 50 07
  431. 62 11 19 38 30 43 51 06 
  432. 04 53 45 28 36 21 13 60
  433. 05 52 44 29 37 20 12 61
  434. 59 14 22 35 27 46 54 03
  435. 58 15 23 34 26 47 55 02
  436. 08 49 41 32 40 17 09 64
  437.  
  438. References:
  439.     "Magic Squares and Cubes"
  440.     W.S. Andrews
  441.     The Open Court Publishing Co.
  442.     Chicago, 1908
  443.  
  444.     "Mathematical Recreations"
  445.     M. Kraitchik
  446.     Dover
  447.     New York, 1953
  448.  
  449.  
  450.  
  451.  
  452. ==> arithmetic/pell.p <==
  453. Find integer solutions to x^2 - 92y^2 = 1.
  454.  
  455. ==> arithmetic/pell.s <==
  456. x=1        y=0
  457. x=1151     y=120
  458. x=2649601  y=276240
  459. etc.
  460.  
  461. Each successive solution is about 2300 times the previous
  462. solution;  they are every 8th partial fraction (x=numerator,
  463. y=denominator) of the continued fraction for sqrt(92) = 
  464. [9,  1,1,2,4,2,1,1,18,  1,1,2,4,2,1,1,18,  1,1,2,4,2,1,1,18, ...]
  465.  
  466. Once you have the smallest positive solution (x1,y1) you
  467. don't need to "search" for the rest.  You can obtain the nth positive
  468. solution (xn,yn) by the formula
  469.  
  470. (x1 + y1 sqrt(92))^n = xn + yn sqrt(92).
  471.  
  472. See Niven & Zuckerman's An Introduction to the Theory of Numbers.
  473. Look in the index under Pell's equation.
  474.  
  475. ==> arithmetic/prime/arithmetic.progression.p <==
  476. Is there an arithmetic progression of 20 or more primes?
  477.  
  478. ==> arithmetic/prime/arithmetic.progression.s <==
  479. There is an arithmetic progression of 21 primes:
  480.     142072321123 + 1419763024680 i, 0 <= i < 21.
  481.  
  482. It was discovered on 30 November 1990, by programs running in the background
  483. on a network of Sun 3 workstations in the Department of Computer Science,
  484. University of Queensland, Australia.
  485.  
  486. See: Andrew Moran and Paul Pritchard, The design of a background job
  487. on a local area network, Procs. 14th Australian Computer Science Conference,
  488. 1991, to appear.
  489.  
  490. ==> arithmetic/prime/consecutive.composites.p <==
  491. Are there 10,000 consecutive non-prime numbers?
  492.  
  493. ==> arithmetic/prime/consecutive.composites.s <==
  494. 9973!+2 through 9973!+10006 are composite.
  495.  
  496. ==> arithmetic/sequence.p <==
  497. Prove that all sets of n integers contain a subset whose sum is divisible by n.
  498.  
  499. ==> arithmetic/sequence.s <==
  500. Consider the set of remainders of the partial sums a(1) + ... + a(i).
  501. Since there are n such sums, either one has remainder zero (and we're
  502. thru) or 2 coincide, say the i'th and j'th.  In this case, a(i+1) +
  503. ... + a(j) is divisible by n.  (note this is a stronger result since
  504. the subsequence constructed is of *adjacent* terms.)  Consider a(1)
  505. (mod n), a(1)+a(2) (mod n), ..., a(1)+...+a(n) (mod n).  Either at
  506. some point we have a(1)+...+a(m) = 0 (mod n) or else by the pigeonhole
  507. principle some value (mod n) will have been duplicated.  We win either
  508. way.
  509.  
  510. ==> arithmetic/sum.of.cubes.p <==
  511. Find two fractions whose cubes total 6.
  512.  
  513. ==> arithmetic/sum.of.cubes.s <==
  514. Restated:  
  515. Find X, Y, minimum Z (all positive integers) where
  516. (X/Z)^3 + (Y/Z)^3 = 6
  517.  
  518. Again, a generalized solution would be nice.
  519.  
  520. You are asking for the smallest z s.t. x^3 + y^3 = 6*z^3 and x,y,z in Z+.
  521. In general, questions like these are extremely difficult; if you're
  522. interested take a look at books covering Diophantine equations
  523. (especially Baker's work on effective methods of computing solutions).
  524.  
  525. Dudeney mentions this problem in connection with #20 in _The Canterbury
  526. Puzzles_; the smallest answer is (17/21)^3 + (37/21)^3 = 6.
  527.  
  528. For the interest of the readers of this group I'll quote:
  529.  
  530.    "Given a known case for the expression of a number as the sum or
  531. difference of two cubes, we can, by formula, derive from it an infinite
  532. number of other cases alternately positive and negative.  Thus Fermat,
  533. starting from the known case 1^3 + 2^3 = 9 (which we will call a
  534. fundamental case), first obtained a negative solution in bigger
  535. figures, and from this his positive solution in bigger figures still.
  536. But there is an infinite number of fundamentals, and I found by trial
  537. a negative fundamental solution in smaller figures than his derived
  538. negative solution, from which I obtained the result shown above.  That
  539. is the simple explanation."
  540.  
  541. In the above paragraph Dudeney is explaining how he derived (*by hand*)
  542. that (415280564497/348671682660)^3 + (676702467503/348671682660)^3 = 9.
  543.  
  544. He continues:
  545.  
  546. "We can say of any number up to 100 whether it is possible or not to
  547. express it as the sum of two cubes, except 66.  Students should read
  548. the Introduction to Lucas's _Theorie des Nombres_, p. xxx."
  549.  
  550. "Some years ago I published a solution for the case 6 = (17/21)^3 +
  551. (37/21)^3, of which Legendre gave at some length a 'proof' of
  552. impossibility; but I have since found that Lucas anticipated me in
  553. a communication to Sylvester."
  554.  
  555. ==> arithmetic/tests.for.divisibility/eleven.p <==
  556. What is the test to see if a number is divisible by eleven?
  557.  
  558.  
  559. ==> arithmetic/tests.for.divisibility/eleven.s <==
  560. If the alternating sum of the digits is divisible by eleven, so is the number.
  561.  
  562. For example, 1639 leads to 9 - 3 + 6 - 1 = 11, so 1639 is divisible by 11.
  563.  
  564. Proof:
  565. Every integer n can be expressed as 
  566. n = a1*(10^k) + a2*(10^k-1)+ .....+ a_k+1
  567. where a1, a2, a3, ...a_k+1 are integers between 0 and 9.
  568. 10 is congruent to -1 mod(11).
  569. Thus if (-1^k)*a1 + (-1^k-1)*a2 + ...+ (a_k+1) is congruent to 0mod(11) then 
  570. n is divisible by 11.
  571.  
  572. ==> arithmetic/tests.for.divisibility/nine.p <==
  573. What is the test to see if a number is divisible by nine?
  574.  
  575. ==> arithmetic/tests.for.divisibility/nine.s <==
  576. If the sum of the digits is divisible by nine, so is the number.
  577.  
  578. Proof:
  579. Every integer n can be expressed as 
  580. n = a1*(10^k) + a2*(10^k-1)+ .....+ a_k+1
  581. where a1, a2, a3, ...a_k+1 are integers between 0 and 9.
  582. Note that 10 is congruent to 1 (mod 9). Thus 10^k is congruent to 1 (mod 9) for
  583. every k >= 0.
  584. Thus n is congruent to (a1+a2+a3+....+a_k+1) mod(9).
  585. Hence (a1+a2+...+a_k+1) is divisible by 9 iff n is divisible by 9.
  586.  
  587. ==> arithmetic/tests.for.divisibility/seven.p <==
  588. What is the test to see if a number is divisible by 7?
  589.  
  590. ==> arithmetic/tests.for.divisibility/seven.s <==
  591. Take the last digit (n mod 10) and double it.
  592. Take the rest of the digits (n div 10) and subtract the doubled last
  593.     digit from it.
  594. The resulting number is divisible by 7 iff the original number
  595.     is divisible by 7.
  596.  
  597. Example:  Take 2009.
  598.           Subtract (2009 mod 10) * 2 from (2009 div 10)
  599.                            -  9  * 2   +   200
  600.                             = 182
  601.           Subtract (182 mod 10)  * 2 from (182 div 10)
  602.                            -  2  * 2   +   18
  603.                             = 14
  604.           so 2009 is divisible by 7.
  605.  
  606. ==> arithmetic/tests.for.divisibility/three.p <==
  607. Prove that if a number is divisible by 3, the sum of its digits is likewise.
  608.  
  609. ==> arithmetic/tests.for.divisibility/three.s <==
  610. First, prove 10^N = 1 mod 3 for all integers N >= 0.
  611. 1 = 1 mod 3. 10 = 1 mod 3. 10^N = 10^(N-1) * 10 = 10^(N-1) mod 3.
  612. QED by induction. 
  613. Now let D[0] be the units digit of N, D[1] the tens digit, etc.
  614. Now N = Summation From k=0 to k=inf of D[k]*10^k.
  615. Therefore N mod 3 = Summation from k=0 to k=inf of D[k] mod 3. QED
  616.  
  617. ==> combinatorics/coinage/combinations.p <==
  618. How many ways are there to make change for a dollar?  Count
  619. combinations of coins, not permuations.
  620.  
  621. ==> combinatorics/coinage/combinations.s <==
  622. Assuming that you had coins of one cent, five cents, ten cents, 25 cents,
  623. 50 cents, and 100 cents, there are 293 ways to make change for a dollar.
  624. This can be calculated by determining the number of ways to make change
  625. using only a penny and then a penny and nickel, then penny, nickel, and
  626. dime, etc.
  627.  
  628. The table is shown below:
  629.  
  630. Amount  00 05 10 15 20 25 30 35 40 45 50 55 60 65  70  75  80  85  90  95  100
  631. Coins  
  632. .01      1  1  1  1  1  1  1  1  1  1  1  1  1  1   1   1   1   1   1   1   1
  633. .05      1  2  3  4  5  6  7  8  9 10 11 12 13 14  15  16  17  18  19  20  21
  634. .10      1  2  4  6  9 12 16 20 25 30 36 42 49 56  64  72  81  90 100 110 121
  635. .25      1  2  4  6  9 13 18 24 31 39 49 60 73 87 103 121 141 163 187 214 242
  636. .50      1  2  4  6  9 13 18 24 31 39 49 62 77 93 112 134 159 187 218 253 292
  637. 1.0      1  2  4  6  9 13 18 24 31 39 49 62 77 93 112 134 159 187 218 253 293
  638.  
  639. The meaning of each entry is as follows:
  640. If you wish to make change for 50 cents using only pennies, nickels and dimes,
  641. go to the .10 row and the 50 column to obtain 36 ways to do this.
  642.  
  643. To calculate each entry, you start with the pennies.  There is exactly one
  644. way to make change for every amount.  Then calculate the .05 row by adding 
  645. the number of ways to make change for the amount using pennies plus the number
  646. of ways to make change for five cents less using nickels and pennies.  This 
  647. continues on for all denominations of coins.  
  648.  
  649. An example, to get change for 75 cents using all coins up to a .50, add the
  650. number of ways to make change using only .25 and down (121) and the number of
  651. ways to make change for 25 cents using coins up to .50 (13).  This yields the
  652. answer of 134.
  653.  
  654. ==> combinatorics/coinage/dimes.p <==
  655. "Dad wants one-cent, two-cent, three-cent, five-cent, and ten-cent
  656. stamps.  He said to get four each of two sorts and three each of the
  657. others, but I've forgotten which.  He gave me exactly enough to buy
  658. them; just these dimes."  How many stamps of each type does Dad want?
  659. [J.A.H. Hunter]
  660.  
  661. ==> combinatorics/coinage/dimes.s <==
  662. The easy way to solve this is to sell her three each, for
  663. 3x(1+2+3+5+10) = 63 cents.  Two more stamps must be bought, and they
  664. must make seven cents (since 17 is too much), so the fourth stamps are
  665. a two and a five.
  666.  
  667. ==> combinatorics/coinage/impossible.p <==
  668. What is the smallest number of coins that you can't make a dollar with?
  669. I.e., for what N does there not exist a set of N coins adding up to a dollar?
  670. It is possible to make a dollar with 1 current U.S. coin (a Susan B. Anthony),
  671. 2 coins (2 fifty cent pieces), 3 coins (2 quarters and a fifty cent piece),
  672. etc.  It is not possible to make exactly a dollar with 101 coins.
  673.  
  674. ==> combinatorics/coinage/impossible.s <==
  675. The answer is 77:
  676.  
  677. a) 5c  = 1 or 5;
  678. b) 10c = 1 or 2 a's (1,2,6,10)
  679. c) 25c = 1 or 2 b's + 1 a
  680. d) 50c = 1 or 2 c's
  681. e) $1  = 1 or 2 d's
  682.  
  683. total    penny    nickle    dime    quarter    half
  684. 5        1    2    1    1
  685. 6        3    1    1    1
  686. 7        5        1    1
  687. 8        4    3        1
  688. 9        6    2        1
  689. 10        8    1        1
  690. 11        10            1
  691. 12        7    4    1
  692. 13        9    3    1
  693. 14        11    2    1
  694. 15        13    1    1
  695. 16        15        1
  696. 17        14    3
  697. 18        16    2
  698. 19        18    1
  699. 20        20
  700. 21    5    13    3
  701. 22    5    15    2
  702. 23    5    17    1
  703. 24    5    19
  704. 25    10    12    3
  705. 26    10    14    2
  706. 27    10    16    1
  707. 28    10    18
  708. 29    15    11    3
  709. 30    15    13    2
  710. 31    15    15    1
  711. 32    15    17
  712. 33    20    10    3
  713. 34    20    12    2
  714. 35    20    14    1
  715. 36    20    16
  716. 37    25    9    3
  717. 38    25    11    2
  718. 39    25    13    1
  719. 40    25    15
  720. 41    30    8    3
  721. 42    30    10    2
  722. 43    30    12    1
  723. 44    30    14
  724. 45    35    7    3
  725. 46    35    9    2
  726. 47    35    11    1
  727. 48    35    13
  728. 49    40    6    3
  729. 50    40    8    2
  730. 51    40    10    1
  731. 52    40    12
  732. 53    45    5    3
  733. 54    45    7    2
  734. 55    45    9    1
  735. 56    45    11
  736. 57    50    4    3
  737. 58    50    6    2
  738. 59    50    8    1
  739. 60    50    10
  740. 61    55    3    3
  741. 62    55    5    2
  742. 63    55    7    1
  743. 64    55    9
  744. 65    60    2    3
  745. 66    60    4    2
  746. 67    60    6    1
  747. 68    60    8
  748. 69    65    1    3
  749. 70    65    3    2
  750. 71    65    5    1
  751. 72    65    7
  752. 73    70        3
  753. 74    70    2    2
  754. 75    70    4    1
  755. 76    70    6
  756. 77    can't be done
  757. 78    75    1    2
  758. 79    75    3    1
  759. 80    75    5
  760. 81    can't be done
  761. 82    80        2
  762. 83    80    2    1
  763. 84    80    4    
  764. 85    can't be done
  765. 86    can't be done
  766. 87    85    1    1
  767. 88    85    3    
  768. 89    can't be done
  769. 90    can't be done
  770. 91    90        1
  771. 92    90    2
  772. 93-95    can't be done
  773. 96    95    1
  774. 97-99    can't be done
  775. 100    100
  776.  
  777. ==> combinatorics/color.p <==
  778. An urn contains n balls of different colors.  Randomly select a pair, repaint
  779. the first to match the second, and replace the pair in the urn.  What is the
  780. expected time until the balls are all the same color?
  781.  
  782. ==> combinatorics/color.s <==
  783. (n-1)^2.
  784.  
  785. If the color classes have sizes k1, k2, ..., km, then the expected number of
  786. steps from here is (dropping the subscript on k):
  787.  
  788.      2               k(k-1)              (j-1) (k-j)
  789. (n-1)  -  SUM      ( ------  +   SUM   --------------- )
  790.          classes,      2        1<j<k      (n-j)
  791.       class.size=k
  792.  
  793. The verification goes roughly as follows.  Defining  phi(k) as  (k(k-1)/2 +
  794. sum[j]...), we first show that  phi(k+1) + phi(k-1) - 2*phi(k) = (n-1)/(n-k)
  795. except when k=n; the k(k-1)/2 contributes 1, the term j=k contributes
  796. (j-1)/(n-j)=(k-1)/(n-k), and the other summands j<k contribute nothing.
  797. Then we say that the expected change in phi(k) on a given color class is
  798. k*(n-k)/(n*(n-1)) times (phi(k+1) + phi(k-1) - 2*phi(k)), since with
  799. probability k*(n-k)/(n*(n-1)) the class goes to size k+1 and with the same
  800. probability it goes to size k-1.  This expected change comes out to k/n.
  801. Summing over the color classes (and remembering the minus sign), the
  802. expected change in the "cost from here" on one step is -1, except when we're
  803. already monochromatic, where the handy exception k=n kicks in.
  804.  
  805. One can rewrite the contribution from k as
  806.  
  807.    (n-1) SUM (k-j)/(n-j)
  808.         0<j<k
  809.  
  810. which incorporates both the k(k-1)/2 and the previous sum over j.
  811. That makes the proof a little cleaner.
  812.  
  813. ==> combinatorics/full.p <==
  814. Consider a string that contains all substrings of length n.  For example,
  815. for binary strings with n=2, a shortest string is 00110 -- it contains 00,
  816. 01, 10 and 11 as substrings.  Find the shortest such strings for all n.
  817.  
  818. ==> combinatorics/full.s <==
  819. Knuth, Volume 2 Seminumerical Algorithms, section 3.2.2 discusses this problem.
  820. He cites the following results:
  821. Shortest length: m^n + n - 1, where m = number of symbols in the language.
  822. Algorithms:
  823. [Exercise 7, W. Mantel, 1897]
  824. The binary sequence is the LSB of X computed by the MIX program:
  825.     LDA X
  826.     JANZ *+2
  827.     LDA A
  828.     ADD X
  829.     JNOV *+3
  830.     JAZ *+2
  831.     XOR A
  832.     STA X
  833. [Exercise 10, M. H. Martin, 1934]
  834. Set x[1] = x[2] = ... = x[n] = 0.  Set x[i+1] = largest value < n such that
  835. substring of n digits ending at x[i+1] does not occur earlier in string.
  836. Terminate when this is not possible.
  837.  
  838. If we instead consider the strings as circular, we have a well known
  839. problem whose solution is given by any hamiltonian cycle in the de
  840. Bruijn (or Good) graph of dimension K.  (Or equivalently an eulerian
  841. circuit in the de Bruijn graph of dimension K-1) As a string of length
  842. 2^K is produced, it must be optimal, and any shortest sequence must be
  843. an eulerian circuit in a dB graph.
  844.  
  845. The de Bruijn graph Tn has as its vertex set the binary n-strings.
  846. Directed edges join n-strings that may be derived by deleting the left
  847. most digit and appending a 0 or 1 to the right end.  de Bruijn + van
  848. Ardenne-Ehrenfest (in 1951) counted the number of eulerian circuits in
  849. Tn. There are 2^(2^(n-1)-n) of them.
  850.  
  851. Some examples:
  852. K=2 1100
  853. K=3 11101000
  854. K=4 1111001011010000
  855.  
  856. The solution to the above problem (non-circular strings) can be found
  857. by duplicating the first K-1 digits of the solution string at the end
  858. of the string.  These are not the only solutions, but they
  859. are of minimum length: 2^K + K-1.  
  860.  
  861. We can obtain a lower bound for the optimal sequence for the general case as
  862. follows:
  863.  
  864. Consider first the simpler case of breaking into an answer machine which
  865. accepts d+1 digits, values 0 to n-1.  We wish to find the minimal universal
  866. code that will allow us access to any such answering machine.
  867.  
  868. Let us construct a digraph G = (V,E), where the n^d vertices are labelled
  869. with a d sequence of digits.  Notation: let [v_{i,1},v_{i,2},...,v_{i,d}]
  870. denote the labelling on node v_i.  An edge e = (v_i, v_j) is in E iff for k
  871. in 1, ..., d-1: v_{i,k+1} = v_{j,k}, i.e., the last d-1 digits in the
  872. labelling of the initial vertex of e is identical with the first d-1 digits
  873. in the labelling of the terminal vertex of e.  We associate with each edge a
  874. value, t(e) = v_{j,d}, the last digit in the labelling of the terminal
  875. vertex.
  876.  
  877. The intuition goes as follows:  we are going to perform a Euler circuit of
  878. the digraph, where the label on the current vertex gives the last d digits
  879. in the output sequence so far.  If we make a transition on edge e, we output
  880. the tone/digit t(e) as the next output value, thus preserving the invariant
  881. on the labelling.
  882.  
  883. How do we know that a Euler circuit exists?  Simple:  a connected digraph
  884. has an Euler circuit iff for all vertices v: indegree(v) = outdegree(v).
  885. This property is trivially true for this digraph.
  886.  
  887. So, in order to generate a universal code for the AM, we simply output 0^d
  888. (to satisfy the precondition for being in vertex [0,...,0]), and perform an
  889. Euler circuit starting at node [0,...,0].
  890.  
  891. Now, the total length of the universal sequence is just the number of edges
  892. traversed in the Euler circuit plus the initial precondition sequence, or
  893. n^d * n + d (number of vertices times the out-degree) or n^{d+1} + d.  That
  894. this is a minimal sequence is obvious.
  895.  
  896. Next, let us consider the machine AM' where the security code is of the form
  897. [0...n-1]^d [0...m-1], i.e., d digits ranging from 0 to n-1, followed by a
  898. terminal digit ranging from 0 to m-1, m < n.
  899.  
  900. We build a digraph G = (V, E) similar to the construction above, except for
  901. the following:  an edge e is in E iff t(e) in 0 to m-1.  This digraph is
  902. clearly non-Eulerian.  In particular, there are two classes of vertices:
  903.  
  904. (1) v is of the form [0...n-1]^{d-1} [0...m-1]  (``fat'' vertices)
  905.  
  906.     and
  907.  
  908. (2) v is of the form [0...n-1]^{d-1} [m...n-1]  (``thin'' vertices)
  909.  
  910. Observations:  there are (n^{d-1} * m) fat vertices, and (n^{d-1} * (n-m))
  911. thin vertices.  All vertices have out-degree of m.  Fat vertices have
  912. in-degrees of n, and thin vertices have in-degrees of 0.  Color all the
  913. edges blue.
  914.  
  915. The question now becomes:  can we put a bound on how many new (red) edges
  916. must we add to G in order to make a blue edge covering path possible?
  917. (Instead of thinking of edges being traversed multiple times in the blue
  918. edge covering path, we allow multiple edges between vertices and allow each
  919. edge to be traversed once.)  Note that, in this procedure, we add edges only
  920. if it is allowed (the vertex labelling constraint).  We will first obtain a
  921. lower bound on the length of a blue covering circuit, and then transform it
  922. into a bound for arbitrary blue covering paths.
  923.  
  924. Clearly, we must add at least (n-m)*(n^{d-1}*m) edges incident from the fat
  925. vertices.  [ We need (n-m) new out-going edges for each of (n^{d-1}*m)
  926. vertices to bring the out-degree up to the in-degree. ]
  927.  
  928. Let us partition our vertices into sets.  Denote the range [0..m-1] by S,
  929. the range [m..n-1] by L, and the range [0..n-1] by X.
  930.  
  931. Let S_0 = { v: v = [X^{d-1}S] }.  S_0 is just the set of fat vertices.
  932. Define in(S_0) = number of edges from vertices not in S to vertices in S.
  933. Define out(S_0) in the corresponding fashion, and let excess(S_0) =
  934. in(S_0)-out(S_0).  Clearly, excess(S_0) = n^{d-1}m(n-m) from the argument
  935. above.  Generalizing the requirement for Eulerian digraphs, we see that we
  936. must add excess(S_0) edges from S_0 if the blue edges connected to/within
  937. S_0 are to be covered by some circuit (edges may not be travered multiple
  938. times -- we add parallel edges to handle that case).  In particular, edges
  939. from S_0 will be incident on vertices of the form [X^{d-2}SX].  Furthermore,
  940. they can not be [X^{d-2}SS] since that is a subset of S_0 and adding those
  941. edges will not help excess(S_0).  [Now, these edges may be needed if we are
  942. to have a circuit, but we do not consider them since they do not help
  943. excess(S_0).] So, we are forced to add excess(S_0) edges from S_0 to S_1 = {
  944. v: v = [X^{d-2}SL] }.  Color these newly added edges red.
  945.  
  946. Let us define in(S_1), out(S_1) and excess(S_1) as above for the modified
  947. digraph, i.e., including the red excess(S_0) edges that we just added.
  948. Clearly, in(S_1) = out(S_0) = n^{d-1}m(n-m), and out(S_1) = m*|S_1| =
  949. m*n^{d-2}m(n-m), so excess(S_1) = n^{d-2}m(n-m)^2.  Consider S_0 union S_1.
  950. We must add excess(S_1) edges to S_0 union S_1 to make it possible for the
  951. digraph to be covered by a circuit, and these edges must go from {S_0 union
  952. S_1} to S_2 = { v: v = [X^{d-3}SL^2] } by a similar argument as before.
  953. Repeating this partitioning process, eventually we get to S_{d-1} = { v: v =
  954. [SL^{d-1}] }, where union of S_0 to S_{d-1} will need edges to S_d = { v: v
  955. = [L^d] }, where this process terminates.  Note that at this time,
  956. excess(union of S_0 to S_{d-1}) = m(n-m)^d, but in(S_d) = 0 and out(S_d) =
  957. m(n-m)^d, and the process terminates.
  958.  
  959. What have we shown?  Adding up blue edges and the red edges gives us a lower
  960. bound on the total number of edges in a blue-edges covering circuit (not
  961. necessarily Eulerian) in the complete digraph.  This comes out to be
  962. n^{d+1}-(n-m)^{d+1} edges.
  963.  
  964. Next, we note that if we had an optimal path covering all the blue edges, we
  965. can transform it into a circuit by adding d edges.  So, a minimal path can
  966. be no more than d edges shorter than the minimal circuit covering all blue
  967. edges.  [Otherwise, we add d extra edges to make it into a shorter circuit.]
  968.  
  969. So the shortest blue covering path through the digraph is at least
  970. n^{d+1}-{n-m}^{d+1}-d.  With an initial pre-condition sequence of length d
  971. (to establish the transition invariant), the shortest universal answering
  972. machine sequence is of length at least n^{d+1}-(n-m)^{d+1}.
  973.  
  974. While this has not been that constructive, it is easy to see that we can
  975. achieve this bound.  If we looked at the vertices in each of the S_i's, we
  976. just add exactly the edges to S_{i+1} and no more.  The resultant digraph
  977. would be Eulerian, and to find the minimal path we need only start at the
  978. vertex labelled [{n-1}^d], find the Euler circuit, and omit the last d edges
  979. from the tour.
  980.  
  981. ==> combinatorics/gossip.p <==
  982. n people each know a different piece of gossip.  They can telephone each other
  983. and exchange all the information they know (so that after the call they both
  984. know anything that either of them knew before the call).  What is the smallest
  985. number of calls needed so that everyone knows everything?
  986.  
  987. ==> combinatorics/gossip.s <==
  988. 1 for n=2
  989. 3 for n=3
  990. 2n-4 for n>=4
  991.  
  992. This can be achieved as follows: choose four professors (A, B, C, and D) as
  993. the "core group".  Each professor outside the core group phones a member of
  994. the core group (it doesn't matter which); this takes n-4 calls.  Now the
  995. core group makes 4 calls: A-B, C-D, A-C, and B-D.  At this point, each
  996. member of the core group knows everything.  Now, each person outside the
  997. core group calls anybody who knows everything; this again requires n-4
  998. calls, for a total of 2n-4.
  999.  
  1000. The solution to the "gossip problem" has been published several times:
  1001.  
  1002.     1.  R. Tidjeman, "On a telephone problem", Nieuw Arch. Wisk. 3
  1003.         (1971), 188-192.
  1004.  
  1005.     2.  B. Baker and R. Shostak, "Gossips and telephones", Discrete
  1006.         Math. 2 (1972), 191-193.
  1007.  
  1008.     3.  A. Hajnal, E. C. Milner, and E. Szemeredi, "A cure for the
  1009.         telephone disease", Canad Math. Bull 15 (1976), 447-450.
  1010.  
  1011.     4. Kleitman and Shearer, Disc. Math. 30 (1980), 151-156.
  1012.  
  1013.     5.  R. T. Bumby, "A problem with telephones", Siam J. Disc. Meth. 2
  1014.         (1981), 13-18.
  1015.  
  1016. ==> combinatorics/grid.dissection.p <==
  1017. How many (possibly overlapping) squares are in an mxn grid?
  1018.  
  1019. ==> combinatorics/grid.dissection.s <==
  1020. Given an n*m grid with n > m.
  1021.  
  1022. Orient the grid so n is its width.  Divide the grid into two portions, 
  1023. an m*m square on the left and an (n-m)*m rectangle on the right.
  1024. Count the squares that have their upper right-hand corners in the
  1025. m*m square.  There are m^2 of size 1*1, (m-1)^2 of size 2*2, ...
  1026. up to 1^2 of size m*m.  Now look at the n-m columns of lattice points
  1027. in the rectangle on the right, in which we find upper right-hand
  1028. corners of squares not yet counted.  For each column we count m new
  1029. 1*1 squares, m-1 new 2*2 squares, ... up to 1 new m*m square.
  1030.  
  1031. Combining all these counts in summations:
  1032.  
  1033.      m           m
  1034. total = sum i^2 + (n - m) sum i
  1035.     i=1          i=1
  1036.  
  1037.     (2m + 1)(m + 1)m   (n - m)(m + 1)m
  1038.       = ---------------- + ---------------
  1039.         6          2
  1040.  
  1041.       = (3n - m + 1)(m + 1)m/6
  1042.  
  1043. -- David Karr
  1044.  
  1045. ==> combinatorics/subsets.p <==
  1046. Out of the set of integers 1,...,100 you are given ten different
  1047. integers.  From this set, A, of ten integers you can always find two
  1048. disjoint subsets, S & T, such that the sum of elements in S equals the
  1049. sum of elements in T.  Note: S union T need not be all ten elements of
  1050. A.  Prove this.
  1051.  
  1052. ==> combinatorics/subsets.s <==
  1053. First, a couple of points:
  1054.  
  1055. (1) All empty subsets of the 10 integers are disjoint and have the same sum.
  1056.     This doesn't make for a very interesting problem.  Thus, we impose the
  1057.     additional restriction that S and T be non-empty.
  1058. (2) The 10 integers must be pairwise distinct.  Consider, e.g., the 10
  1059.     integers 1, 1, 1, 1, 1, 1, 1, 1, 1, and 1.  There are no non-empty
  1060.     disjoint subsets with equal sums.
  1061.  
  1062. Proof of puzzle:
  1063.  
  1064. There are 2^10 = 1,024 subsets of the 10 integers, but there can be only 901
  1065. possible sums, the number of integers between the minimum and maximum sums.
  1066. With more subsets than possible sums, there must exist at least one sum that
  1067. corresponds to at least two subsets.  Call two subsets with equal sums A and B.
  1068. Let C = A intersect B; define S = A - C, T = B - C.  Then S is disjoint from T,
  1069. and sum(S) = sum(A-C) = sum(A) - sub(C) = sum(B) - sum(C) = sum(B-C) = sum(T).
  1070. QED
  1071.  
  1072. ==> cryptology/Beale.p <==
  1073. What are the Beale ciphers?
  1074.  
  1075. ==> cryptology/Beale.s <==
  1076. The Beale ciphers are one of the greatest unsolved puzzles of all time.
  1077. About 100 years ago, a fellow by the name of Beale supposedly buried two
  1078. wagons-full of silver-coin filled pots in Bedford County, near Roanoke.
  1079. There are local rumors about the treasure being buried near Bedford Lake.
  1080.  
  1081. He wrote three encoded letters telling what was buried, where it was buried,
  1082. and who it belonged to.  He entrusted these three letters to a friend and went
  1083. west.  He was never heard from again.
  1084.  
  1085. Several years later, someone examined the letters and was able to break the
  1086. code used in the second letter.  The code used either the text from the 
  1087. Declaration of Independence.  A number in the letter indicated which word
  1088. in the document was to be used.  The first letter of that word replaced the
  1089. number.  For example, if the first three words of the document were "We
  1090. hold these truths", the number 3 in the letter would represent the letter t.
  1091.  
  1092. One of the remaining letters supposedly contains directions on how to find
  1093. the treasure.  To date, no one has solved the code.  It is believed that
  1094. both of the remaining letters are encoded using either the same document
  1095. in a different way, or another very public document.
  1096.  
  1097. For those interested, write to:
  1098.     The Beale Cypher Association
  1099.     P.O. Box 975
  1100.     Beaver Falls, PA 15010
  1101.  
  1102. Item #904 is the 1885 pamphlet version ($5.00).  #152 is the 
  1103. Cryptologia article by Gillogly that argues the hoax side ($2.00).
  1104. A year's membership is $25, and includes 4 newsletters.
  1105.  
  1106. TEXT for part 1
  1107.  
  1108.            The Locality of the Vault.
  1109.  
  1110. 71,194,38,1701,89,76,11,83,1629,48,94,63,132,16,111,95,84,341
  1111. 975,14,40,64,27,81,139,213,63,90,1120,8,15,3,126,2018,40,74
  1112. 758,485,604,230,436,664,582,150,251,284,308,231,124,211,486,225
  1113. 401,370,11,101,305,139,189,17,33,88,208,193,145,1,94,73,416
  1114. 918,263,28,500,538,356,117,136,219,27,176,130,10,460,25,485,18
  1115. 436,65,84,200,283,118,320,138,36,416,280,15,71,224,961,44,16,401
  1116. 39,88,61,304,12,21,24,283,134,92,63,246,486,682,7,219,184,360,780
  1117. 18,64,463,474,131,160,79,73,440,95,18,64,581,34,69,128,367,460,17
  1118. 81,12,103,820,62,110,97,103,862,70,60,1317,471,540,208,121,890
  1119. 346,36,150,59,568,614,13,120,63,219,812,2160,1780,99,35,18,21,136
  1120. 872,15,28,170,88,4,30,44,112,18,147,436,195,320,37,122,113,6,140
  1121. 8,120,305,42,58,461,44,106,301,13,408,680,93,86,116,530,82,568,9
  1122. 102,38,416,89,71,216,728,965,818,2,38,121,195,14,326,148,234,18
  1123. 55,131,234,361,824,5,81,623,48,961,19,26,33,10,1101,365,92,88,181
  1124. 275,346,201,206,86,36,219,324,829,840,64,326,19,48,122,85,216,284
  1125. 919,861,326,985,233,64,68,232,431,960,50,29,81,216,321,603,14,612
  1126. 81,360,36,51,62,194,78,60,200,314,676,112,4,28,18,61,136,247,819
  1127. 921,1060,464,895,10,6,66,119,38,41,49,602,423,962,302,294,875,78
  1128. 14,23,111,109,62,31,501,823,216,280,34,24,150,1000,162,286,19,21
  1129. 17,340,19,242,31,86,234,140,607,115,33,191,67,104,86,52,88,16,80
  1130. 121,67,95,122,216,548,96,11,201,77,364,218,65,667,890,236,154,211
  1131. 10,98,34,119,56,216,119,71,218,1164,1496,1817,51,39,210,36,3,19
  1132. 540,232,22,141,617,84,290,80,46,207,411,150,29,38,46,172,85,194
  1133. 39,261,543,897,624,18,212,416,127,931,19,4,63,96,12,101,418,16,140
  1134. 230,460,538,19,27,88,612,1431,90,716,275,74,83,11,426,89,72,84
  1135. 1300,1706,814,221,132,40,102,34,868,975,1101,84,16,79,23,16,81,122
  1136. 324,403,912,227,936,447,55,86,34,43,212,107,96,314,264,1065,323
  1137. 428,601,203,124,95,216,814,2906,654,820,2,301,112,176,213,71,87,96
  1138. 202,35,10,2,41,17,84,221,736,820,214,11,60,760
  1139.  
  1140.  
  1141.  
  1142. TEXT for part 2
  1143.  
  1144.         (no title exists for this part)
  1145.  
  1146. 115,73,24,807,37,52,49,17,31,62,647,22,7,15,140,47,29,107,79,84
  1147. 56,239,10,26,811,5,196,308,85,52,160,136,59,211,36,9,46,316,554
  1148. 122,106,95,53,58,2,42,7,35,122,53,31,82,77,250,196,56,96,118,71
  1149. 140,287,28,353,37,1005,65,147,807,24,3,8,12,47,43,59,807,45,316
  1150. 101,41,78,154,1005,122,138,191,16,77,49,102,57,72,34,73,85,35,371
  1151. 59,196,81,92,191,106,273,60,394,620,270,220,106,388,287,63,3,6
  1152. 191,122,43,234,400,106,290,314,47,48,81,96,26,115,92,158,191,110
  1153. 77,85,197,46,10,113,140,353,48,120,106,2,607,61,420,811,29,125,14
  1154. 20,37,105,28,248,16,159,7,35,19,301,125,110,486,287,98,117,511,62
  1155. 51,220,37,113,140,807,138,540,8,44,287,388,117,18,79,344,34,20,59
  1156. 511,548,107,603,220,7,66,154,41,20,50,6,575,122,154,248,110,61,52,33
  1157. 30,5,38,8,14,84,57,540,217,115,71,29,84,63,43,131,29,138,47,73,239
  1158. 540,52,53,79,118,51,44,63,196,12,239,112,3,49,79,353,105,56,371,557
  1159. 211,505,125,360,133,143,101,15,284,540,252,14,205,140,344,26,811,138
  1160. 115,48,73,34,205,316,607,63,220,7,52,150,44,52,16,40,37,158,807,37
  1161. 121,12,95,10,15,35,12,131,62,115,102,807,49,53,135,138,30,31,62,67,41
  1162. 85,63,10,106,807,138,8,113,20,32,33,37,353,287,140,47,85,50,37,49,47
  1163. 64,6,7,71,33,4,43,47,63,1,27,600,208,230,15,191,246,85,94,511,2,270
  1164. 20,39,7,33,44,22,40,7,10,3,811,106,44,486,230,353,211,200,31,10,38
  1165. 140,297,61,603,320,302,666,287,2,44,33,32,511,548,10,6,250,557,246
  1166. 53,37,52,83,47,320,38,33,807,7,44,30,31,250,10,15,35,106,160,113,31
  1167. 102,406,230,540,320,29,66,33,101,807,138,301,316,353,320,220,37,52
  1168. 28,540,320,33,8,48,107,50,811,7,2,113,73,16,125,11,110,67,102,807,33
  1169. 59,81,158,38,43,581,138,19,85,400,38,43,77,14,27,8,47,138,63,140,44
  1170. 35,22,177,106,250,314,217,2,10,7,1005,4,20,25,44,48,7,26,46,110,230
  1171. 807,191,34,112,147,44,110,121,125,96,41,51,50,140,56,47,152,540
  1172. 63,807,28,42,250,138,582,98,643,32,107,140,112,26,85,138,540,53,20
  1173. 125,371,38,36,10,52,118,136,102,420,150,112,71,14,20,7,24,18,12,807
  1174. 37,67,110,62,33,21,95,220,511,102,811,30,83,84,305,620,15,2,108,220
  1175. 106,353,105,106,60,275,72,8,50,205,185,112,125,540,65,106,807,188,96,110
  1176. 16,73,32,807,150,409,400,50,154,285,96,106,316,270,205,101,811,400,8
  1177. 44,37,52,40,241,34,205,38,16,46,47,85,24,44,15,64,73,138,807,85,78,110
  1178. 33,420,505,53,37,38,22,31,10,110,106,101,140,15,38,3,5,44,7,98,287
  1179. 135,150,96,33,84,125,807,191,96,511,118,440,370,643,466,106,41,107
  1180. 603,220,275,30,150,105,49,53,287,250,208,134,7,53,12,47,85,63,138,110
  1181. 21,112,140,485,486,505,14,73,84,575,1005,150,200,16,42,5,4,25,42
  1182. 8,16,811,125,160,32,205,603,807,81,96,405,41,600,136,14,20,28,26
  1183. 353,302,246,8,131,160,140,84,440,42,16,811,40,67,101,102,194,138
  1184. 205,51,63,241,540,122,8,10,63,140,47,48,140,288
  1185.  
  1186. CLEAR for part 2, made human readable.
  1187.  
  1188. I have deposited in the county of Bedford about four miles from
  1189. Bufords in an excavation or vault six feet below the surface
  1190. of the ground the following articles belonging jointly to
  1191. the parties whose names are given in number three herewith.
  1192. The first deposit consisted of ten hundred and fourteen pounds
  1193. of gold and thirty eight hundred and twelve pounds of silver
  1194. deposited Nov eighteen nineteen.  The second was made Dec
  1195. eighteen twenty one and consisted of nineteen hundred and seven
  1196. pounds of gold and twelve hundred and eighty eight of silver,
  1197. also jewels obtained in St. Louis in exchange to save transportation 
  1198. and valued at thirteen [t]housand dollars.  The above 
  1199. is securely packed i[n] [i]ron pots with iron cov[e]rs.  Th[e] vault
  1200. is roughly lined with stone and the vessels rest on solid stone 
  1201. and are covered [w]ith others.  Paper number one describes th[e]
  1202. exact locality of the va[u]lt so that no difficulty will be had
  1203. in finding it.
  1204.  
  1205. CLEAR for part 2, using only the first 480 words of the 
  1206. Declaration of Independence, then blanks filled in by
  1207. inspection.  ALL mistakes shown were caused by sloppy 
  1208. encryption.
  1209.     0----5----10---15---20---25---30---35---40---45---
  1210.   0 ihavedepositedinthecountyofbedfordaboutfourmilesfr
  1211.  50 ombufordsinanexcavationorvaultsixfeetbelowthesurfa
  1212. 100 ceofthegroundthefollowingarticlesbelongingjointlyt
  1213. 150 othepartieswhosenamesaregiveninnumberthreeherewith
  1214. 200 thefirstdepositconsistcdoftenhundredandfourteenpou
  1215. 250 ndsofgoldandthirtyeighthundredandtwelvepoundsofsil
  1216. 300 verdepositednoveighteennineteenthesecondwasmadedec
  1217. 350 eighteentwentyoneandconsistedofnineteenhundredands
  1218. 400 evenpoundsofgoldandtwelvehundredandeightyeightofsi
  1219. 450 lveralsojewelsobtainedinstlouisinexchangetosavetra
  1220. 500 nsportationandvaluedatthirteenrhousanddollarstheab
  1221. 550 oveissecurelypackeditronpotswithironcovtrsthtvault
  1222. 600 isroughlylinedwithstoneandthevesselsrestonsolidsto
  1223. 650 neandarecovereduithotherspapernumberonedescribesth
  1224. 700 cexactlocalityofthevarltsothatnodifficultywillbeha
  1225. 750 dinfindingit
  1226.  
  1227.  
  1228. TEXT for part 3
  1229.  
  1230.          Names and Residences.
  1231.  
  1232. 317,8,92,73,112,89,67,318,28,96,107,41,631,78,146,397,118,98
  1233. 114,246,348,116,74,88,12,65,32,14,81,19,76,121,216,85,33,66,15
  1234. 108,68,77,43,24,122,96,117,36,211,301,15,44,11,46,89,18,136,68
  1235. 317,28,90,82,304,71,43,221,198,176,310,319,81,99,264,380,56,37
  1236. 319,2,44,53,28,44,75,98,102,37,85,107,117,64,88,136,48,154,99,175
  1237. 89,315,326,78,96,214,218,311,43,89,51,90,75,128,96,33,28,103,84
  1238. 65,26,41,246,84,270,98,116,32,59,74,66,69,240,15,8,121,20,77,80
  1239. 31,11,106,81,191,224,328,18,75,52,82,117,201,39,23,217,27,21,84
  1240. 35,54,109,128,49,77,88,1,81,217,64,55,83,116,251,269,311,96,54,32
  1241. 120,18,132,102,219,211,84,150,219,275,312,64,10,106,87,75,47,21
  1242. 29,37,81,44,18,126,115,132,160,181,203,76,81,299,314,337,351,96,11
  1243. 28,97,318,238,106,24,93,3,19,17,26,60,73,88,14,126,138,234,286
  1244. 297,321,365,264,19,22,84,56,107,98,123,111,214,136,7,33,45,40,13
  1245. 28,46,42,107,196,227,344,198,203,247,116,19,8,212,230,31,6,328
  1246. 65,48,52,59,41,122,33,117,11,18,25,71,36,45,83,76,89,92,31,65,70
  1247. 83,96,27,33,44,50,61,24,112,136,149,176,180,194,143,171,205,296
  1248. 87,12,44,51,89,98,34,41,208,173,66,9,35,16,95,8,113,175,90,56
  1249. 203,19,177,183,206,157,200,218,260,291,305,618,951,320,18,124,78
  1250. 65,19,32,124,48,53,57,84,96,207,244,66,82,119,71,11,86,77,213,54
  1251. 82,316,245,303,86,97,106,212,18,37,15,81,89,16,7,81,39,96,14,43
  1252. 216,118,29,55,109,136,172,213,64,8,227,304,611,221,364,819,375
  1253. 128,296,1,18,53,76,10,15,23,19,71,84,120,134,66,73,89,96,230,48
  1254. 77,26,101,127,936,218,439,178,171,61,226,313,215,102,18,167,262
  1255. 114,218,66,59,48,27,19,13,82,48,162,119,34,127,139,34,128,129,74
  1256. 63,120,11,54,61,73,92,180,66,75,101,124,265,89,96,126,274,896,917
  1257. 434,461,235,890,312,413,328,381,96,105,217,66,118,22,77,64,42,12
  1258. 7,55,24,83,67,97,109,121,135,181,203,219,228,256,21,34,77,319,374
  1259. 382,675,684,717,864,203,4,18,92,16,63,82,22,46,55,69,74,112,134
  1260. 186,175,119,213,416,312,343,264,119,186,218,343,417,845,951,124
  1261. 209,49,617,856,924,936,72,19,28,11,35,42,40,66,85,94,112,65,82
  1262. 115,119,233,244,186,172,112,85,6,56,38,44,85,72,32,47,63,96,124
  1263. 217,314,319,221,644,817,821,934,922,416,975,10,22,18,46,137,181
  1264. 101,39,86,103,116,138,164,212,218,296,815,380,412,460,495,675,820
  1265. 952
  1266.  
  1267.  
  1268.  
  1269.  
  1270. Evidence in favor of a hoax-
  1271.    . Too many players.
  1272.    . Inflated quantities of treasure.
  1273.    . Many discrepancies exist in all documents.
  1274.    . The Declaration of Independence is too hokey a key.
  1275.    . Part 3 (list of 30 names) considered too little text.
  1276.    . W.F. Friedman couldn't crack it.
  1277.    . Why even encrypt parts 1 & 3?
  1278.    . Why use multi-part text, and why different keys for each part?
  1279.    . Difficult to keep treasure in ground if 30 men know where it was buried.
  1280.    . Who'd leave it with other than your own family?
  1281.    . The Inn Keeper waited an extra 10 years before opening box with
  1282.       ciphers in it?  Who would do this, curiousity runs too deep in
  1283.       humans?
  1284.    . Why did anybody waste time deciphering paper 2, which had no title?
  1285.       1 & 3 had titles! These should have been deciphered first?
  1286.    . Why not just one single letter?
  1287.    . Statistical analysis show 1&3 similar in very obscure ways, that
  1288.       2 differs.  Did somebody else encipher it?  And why?
  1289.       Check length of keytexts, and forward/backward next word
  1290.       displacement selections.
  1291.    . Who could cross the entire country with that much gold and only
  1292.       10 men and survive back then?
  1293.    . Practically everybody who visited New Mexico before 1821, left
  1294.       by way of the Pearly Gates, as the Spanish got almost every
  1295.       tourist:-)
  1296.  
  1297.  
  1298. References:
  1299.  
  1300.    "The Beale Treasure: A History of a Mystery", by Peter Viemeister,
  1301.        Bedord, VA: Hamilton's, 1987.  ISBN: 0-9608598-3-7.  230 pages.
  1302.    "The Codebreakers", by David Kahn, pg 771, CCN 63-16109.
  1303.       1967.
  1304.    "Gold in the Blue Ridge, The True Story of the Beale Treasure",
  1305.       by P.B. Innis & Walter Dean Innis, Devon Publ. Co., Wash, D.C.
  1306.       1973.
  1307.     "Signature Simulation and Certain Cryptographic Codes", Hammer,
  1308.     Communications of the ACM, 14 (1), January 1971, pp. 3-14.
  1309.     "How did TJB Encode B2?", Hammer, Cryptologia, 3 (1), Jan. 1979, pp. 9-15.
  1310.     "Second Order Homophonic Ciphers", Hammer, Cryptologia, 12 (1) Jan. 1988,
  1311.     pp 11-20.
  1312.  
  1313. ==> cryptology/Feynman.p <==
  1314. What are the Feynman ciphers?
  1315.  
  1316. ==> cryptology/Feynman.s <==
  1317. When I was a graduate student at Caltech, Professor Feynman showed me three
  1318. samples of code that he had been challenged with by a fellow scientist at
  1319. Los Alamos and which he had not been able to crack.  I also was unable to
  1320. crack them.  I posted them to Usenet and Jack C. Morrison of JPL cracked
  1321. the first one.  It is a simple transposition cipher: split the text into
  1322. 5-column pieces, then read from lower right upward.  What results are the
  1323. opening lines of Chaucer's Canterbury Tales in Middle English.
  1324.  
  1325. 1. Easier
  1326. MEOTAIHSIBRTEWDGLGKNLANEA
  1327. INOEEPEYSTNPEUOOEHRONLTIR
  1328. OSDHEOTNPHGAAETOHSZOTTENT
  1329. KEPADLYPHEODOWCFORRRNLCUE
  1330. EEEOPGMRLHNNDFTOENEALKEHH
  1331. EATTHNMESCNSHIRAETDAHLHEM
  1332. TETRFSWEDOEOENEGFHETAEDGH
  1333. RLNNGOAAEOCMTURRSLTDIDORE
  1334. HNHEHNAYVTIERHEENECTRNVIO
  1335. UOEHOTRNWSAYIFSNSHOEMRTRR
  1336. EUAUUHOHOOHCDCHTEEISEVRLS
  1337. KLIHIIAPCHRHSIHPSNWTOIISI
  1338. SHHNWEMTIEYAFELNRENLEERYI
  1339. PHBEROTEVPHNTYATIERTIHEEA
  1340. WTWVHTASETHHSDNGEIEAYNHHH
  1341. NNHTW
  1342.  
  1343. 2. Harder
  1344. XUKEXWSLZJUAXUNKIGWFSOZRAWURO
  1345. RKXAOSLHROBXBTKCMUWDVPTFBLMKE
  1346. FVWMUXTVTWUIDDJVZKBRMCWOIWYDX
  1347. MLUFPVSHAGSVWUFWORCWUIDUJCNVT
  1348. TBERTUNOJUZHVTWKORSVRZSVVFSQX
  1349. OCMUWPYTRLGBMCYPOJCLRIYTVFCCM
  1350. UWUFPOXCNMCIWMSKPXEDLYIQKDJWI
  1351. WCJUMVRCJUMVRKXWURKPSEEIWZVXU
  1352. LEIOETOOFWKBIUXPXUGOWLFPWUSCH
  1353.  
  1354. 3. New Message
  1355. WURVFXGJYTHEIZXSQXOBGSV
  1356. RUDOOJXATBKTARVIXPYTMYA
  1357. BMVUFXPXKUJVPLSDVTGNGOS
  1358. IGLWURPKFCVGELLRNNGLPYT
  1359. FVTPXAJOSCWRODORWNWSICL
  1360. FKEMOTGJYCRRAOJVNTODVMN
  1361. SQIVICRBICRUDCSKXYPDMDR
  1362. OJUZICRVFWXIFPXIVVIEPYT
  1363. DOIAVRBOOXWRAKPSZXTZKVR
  1364. OSWCRCFVEESOLWKTOBXAUXV
  1365. B
  1366.  
  1367. Chris Cole
  1368. Peregrine Systems
  1369. uunet!peregrine!chris
  1370.  
  1371. ==> cryptology/Voynich.p <==
  1372. What are the Voynich ciphers?
  1373.  
  1374.